package com.blank.shop.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author _blank
 */
@Configuration
public class CustomizeRoutingRulesConfig {

    /**
     * 编码实现路由规则
     *
     * @param builder builder
     * @return org.springframework.cloud.gateway.route.RouteLocator
     * @see <a href="https://docs.spring.io/spring-cloud-gateway/docs/2.2.9.RELEASE/reference/html/#configuration">configuration</a>
     */
    @Bean
    public RouteLocator customBaiDuRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("path_route_bidu_guonei", ps -> ps.path("/guonei").uri("https://news.baidu.com/guonei"))
                .route("path_route_bidu_guoji", ps -> ps.path("/guoji").uri("https://news.baidu.com/guoji"))
                .route("path_route_msft", ps -> ps.path("/msft").uri("https://cn.bing.com/"))
                .route("path_route_rilb", ps -> ps.path("/rilb").uri("https://www.jianshu.com/p/64fa66f4524f"))
                .build();
    }

}
